#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

#define INF 0x3f3f3f3f

#define TRACE(x...)  
#define PRINT(x...) TRACE(printf(x))

int n;
char s[550][60];
int fw[550][550];
int sizes[550];
int M;
int flag;

#define rep(i,n) for (int i=0; i<n; i++)

int addLet(int a, int b) {
	if (sizes[a]<sizes[b]-1) return 0;
	if (sizes[b]<sizes[a]-1) return 0;

	int flag=0;

	for (int i=0, j=0; i<sizes[a] && j<sizes[b]; i++, j++) {
		if (s[a][i]==s[b][j]) continue;
		if (flag) return 0;
		flag=1;

		if (sizes[a]>sizes[b]) {
			if ((i+1)<sizes[a]) { 
				if (s[a][++i]==s[b][j]) continue; 
				else return 0;
			}
			else return 1;
		}			
		
		if (sizes[b]>sizes[a]) {
			if ((j+1)<sizes[b]) { 
				if (s[a][i]==s[b][++j]) continue; 
				else return 0;
			}
			else return 1;
		}			
	}

	return 1;
}

int main() {
	while (1) {
		scanf("%d", &n);
	
		if (!n) break;
	
		rep(i,n) scanf(" %s", s[i]);
		rep(i,n) sizes[i]=strlen(s[i]);

		rep(i,n) rep(j,n) fw[i][j]=INF;

		rep(i,n) {
			rep(j,n) {
				flag=0;

				if (sizes[i]==sizes[j]) {
					rep(k,sizes[i]) {
						if (s[i][k]==s[j][k]) continue;
						if (flag) {
							flag=0; break;
						}				
						flag=1;
					}
				}
				else if (sizes[i]==(sizes[j]+1) || sizes[j]==(sizes[i]+1)) {
					flag=addLet(i,j);					
				}
				else continue;

				if (flag) { 
					fw[i][j]=1;
					PRINT("%s %s\n", s[i], s[j]); 
				}
			}
		}


		TRACE(
			rep(i,n) {
				rep(j,n) printf("%d ", fw[i][j]);
				printf("\n");
			}
		);

		rep(k,n) {
			rep(i,n) {
				rep(j,n) fw[i][j] = min(fw[i][j], fw[i][k]+fw[k][j]);
			}
		}

		TRACE(
			printf("After FW:\n");
			rep(i,n) {
				rep(j,n) printf("%d ", fw[i][j]);
				printf("\n");
			}
		);

		M=0;

		rep(i,n) {
			rep(j,n) { 
				if (i==j) continue;
				else if (M<fw[i][j] && fw[i][j]!=INF) M=fw[i][j];
			}
		}
		
		if (M!=INF) printf("%d\n", M+1);
		else printf("1\n");
	}

	return 0;
}
